package com.sthz.facepay.util;

import com.sthz.facepay.enums.ApiResultEnum;
import com.sthz.facepay.model.result.ApiResult;

/**
 * web层统一返回工具类
 * @author luli
 * @version jdk 1.8
 * @date 2019/7/12 11:05
 */
public class ApiResultUtil {

    /**
     * 获取请求成功响应的ApiResult
     * @param data
     * @return
     */
    public static ApiResult getApiResult(Object data) {
        return getApiResult(data, ApiResultEnum.SUCCESS.getErrCode(), ApiResultEnum.SUCCESS.getErrMsg());
    }

    /**
     * 获取其他请求响应的ApiResult
     * @param code
     * @param msg
     * @return
     */
    public static ApiResult getApiResult(int code,String msg) {
        return getApiResult(null, code, msg);
    }

    /**
     * 枚举信息转统一返回对象
     * @param apiResultEnum
     * @return
     */
    public static ApiResult getApiResult(ApiResultEnum apiResultEnum){
        return  getApiResult(apiResultEnum.getErrCode(),apiResultEnum.getErrMsg());
    }


    public static ApiResult getApiResult(Object data, int code, String msg) {
        ApiResult apiResult = new ApiResult(data);
        apiResult.setErrCode(code);
        apiResult.setErrMsg(msg);
        return apiResult;
    }


}
